package com.zlkj.pro.modular.api.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import com.zlkj.pro.modular.api.model.dto.ResourcesDTO;
import com.zlkj.pro.modular.api.model.vo.ResourcesVO;
import com.zlkj.pro.modular.api.service.ResourcesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.zlkj.pro.core.consts.ProjectConstants.SERVICE_API_PREFIX;

/**
 * @author 孙铭泽
 * @date 2022/8/31
 * @time 16:52
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@ApiResource(name = "资源API", path = SERVICE_API_PREFIX + "/resources")
public class ResourcesController {
    private final ResourcesService resourcesService;

    @GetResource(name = "按标识查找资源", path = "/findResourceByIdentifies", requiredPermission = false, requiredLogin = false)
    public ResponseData findResourceByIdentifies(@Validated(ResourcesDTO.Identifies.class) ResourcesDTO resourcesDTO) {
        Map<String, ResourcesVO> restData = resourcesService.findResourceByIdentifies(resourcesDTO);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "按标识查找唯一资源", path = "/findResourceByIdentifiesOnly", requiredPermission = false, requiredLogin = false)
    public ResponseData findResourceByIdentifiesOnly(@Validated(ResourcesDTO.Identifies.class) ResourcesDTO resourcesDTO) {
        ResourcesVO restData = resourcesService.findResourceByIdentifiesOnly(resourcesDTO);
        return new SuccessResponseData(restData);
    }
}
